package com.hqyj.product.controller;


import com.hqyj.product.model.ProductPlan;
import frame.product.controller.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
@RequestMapping("/planController")
public class planController extends BaseController {
    @RequestMapping("/planlist.do")
    public String list(HttpServletRequest request, HttpServletResponse response, HttpSession session, Model model, ProductPlan productPlan) {
        //1.接收数据;
        System.out.println("-----------planlist-------");
        //3.调用业务;

        List<ProductPlan> productPlan_dbList = productPlanService.queryAllProductPlan();
        System.out.println(productPlan_dbList);
        model.addAttribute("productPlan_dbList", productPlan_dbList);
        //2.跳转页面;
        return "view/product/productPlan/productPlanList";
    }

    @RequestMapping("/add.do")
    public String add(HttpServletRequest request, HttpServletResponse response, HttpSession session, Model model, ProductPlan productPlan) {
        //1.接收数据;
//        System.out.println("-----------add------" + productPlan);
        //3.调用业务;
        int n = productPlanService.addProductPlanByProductPlan(productPlan);

        //2.跳转页面;
        List<ProductPlan> productPlan_dbList = productPlanService.queryAllProductPlan();
        model.addAttribute("productPlan_dbList", productPlan_dbList);
        return "/view/product/productPlan/productPlanList";
    }

    @RequestMapping("/delete.do")
    public String delete(HttpServletRequest request, HttpServletResponse response, HttpSession session, Model model, ProductPlan productPlan, String idStr) {
        //1.接收数据;
        System.out.println("-----------delete------" + idStr);
        //3.调用业务;
        //字符类型转数字类型
        int id = Integer.parseInt(idStr);
        //业务
        int n = productPlanService.deleteProductPlanById(id);

        //2.跳转页面;
        List<ProductPlan> productPlan_dbList = productPlanService.queryAllProductPlan();
        model.addAttribute("productPlan_dbList", productPlan_dbList);
        return "view/product/productPlan/productPlanList";
    }

    @RequestMapping("/updateUI.do")
    public String updateUI(HttpServletRequest request, HttpServletResponse response, HttpSession session, Model model, ProductPlan productPlan, String idStr) {
        //字符类型转数字类型
        int productPlanId = Integer.parseInt(idStr);
        //业务
        ProductPlan productPlan_db = productPlanService.queryProductPlanById(productPlanId);
        System.out.println("-----------updateUI------" + productPlan_db);
        model.addAttribute("productPlan", productPlan_db);
        //2.跳转页面;
        return "view/product/productPlan/updateProductPlan";
    }

    @RequestMapping("/update.do")
    public String update(HttpServletRequest request, HttpServletResponse response, HttpSession session, Model model, ProductPlan productPlan, String id) {
        //1.接收数据;
        //字符类型转数字类型
        int pickingListNo = Integer.parseInt(id);


        //3.调用业务;
        int n = productPlanService.updateProductPlanByProductPlan(productPlan);


        //2.跳转页面;
        List<ProductPlan> productPlan_dbList = productPlanService.queryAllProductPlan();
        model.addAttribute("productPlan_dbList", productPlan_dbList);
        return "view/product/productPlan/productPlanList";
    }
}
